package com.hongsen.cn.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.hongsen.cn.Utils.BitmapUtils;
import com.hongsen.cn.base.BaseRecyclerViewHolder;
import com.hongsen.cn.bean.FirstPageFaceCallBackBean;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.ItemPoliceImgBinding;
import com.hongsen.cn.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 警员照片列表
 */
public class PoliceImgAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<FirstPageFaceCallBackBean.RecordsBean> strings = new ArrayList<>();
    private Context mcontext;
    public OnItemClickListener mOnItemClickLitener;


    public PoliceImgAdapter(Context context, List<FirstPageFaceCallBackBean.RecordsBean> strings) {
        this.mcontext = context;
        this.strings = strings;

    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemPoliceImgBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mcontext),
                R.layout.item_police_img, parent, false);
        binding.setAdapter(this);
        return new TourViewHolder(binding);
    }


    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.bindData(strings.get(position));

        TourViewHolder tv = (TourViewHolder) holder;
        if (!TextUtils.isEmpty(strings.get(position).getZp())) {
            tv.imagePhoto.setImageBitmap(BitmapUtils.getBitmap(strings.get(position).getZp()));
        }

        switch (strings.get(position).getDllx()) {
            case "10":
                tv.tvName.setText("[进]"+ strings.get(position).getDlsj().split(" ")[1]);
                break;
            case "20":
                tv.tvName.setText("[出]"+ strings.get(position).getDlsj().split(" ")[1]);
                break;
            case "30":
                tv.tvName.setText("[进]"+ strings.get(position).getDlsj().split(" ")[1]);
                break;
            case "40":
                tv.tvName.setText("[出]"+ strings.get(position).getDlsj().split(" ")[1]);
                break;
            default:

        }


        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<FirstPageFaceCallBackBean.RecordsBean> {
        ItemPoliceImgBinding binding;
        ImageView imagePhoto;
        TextView tvName;

        public TourViewHolder(ItemPoliceImgBinding dataBinding) {
            super(dataBinding.getRoot());
            binding = dataBinding;
            imagePhoto = dataBinding.imagePhoto;
            tvName = dataBinding.tvName;
        }

        @Override
        public void bindData(FirstPageFaceCallBackBean.RecordsBean data) {
            binding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }
}
